import store from "../store";
import Cache from '../utils/cache';
import {
	Debounce
} from '@/utils/validate.js'

function prePage() {
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 1];
	// #ifndef APP-PLUS
	return prePage.route;
	// #endif
	// #ifdef APP-PLUS
	return prePage.$page.fullPath;
	// #endif

}

export const toLogin = Debounce(_toLogin, 800)

function _toLogin(push, pathLogin) {
	
	// #ifndef H5
	store.commit("LOGOUT");
	// #endif
	let path = prePage();

	if (!pathLogin){
		pathLogin = '/pages/users/login/index'
	}
		
	Cache.set('login_back_url', pathLogin);

	// #ifdef MP 
	uni.navigateTo({
		url: '/pages/users/login/index'
	})
	// #endif

}